package soft863.com.mr3;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class mv_avgRd extends Reducer<Text, DoubleWritable,Text,DoubleWritable> {
    @Override
    protected void reduce(Text key, Iterable<DoubleWritable> values, Context context) throws IOException, InterruptedException {
        double sum = 0;
        long t = 0;
        for (DoubleWritable i : values) {
            sum += i.get();
            t += 1;
        }
        double avg = sum/t;
        context.write(key,new DoubleWritable(avg));
    }
}